package cn.iocoder.yudao.module.service.convert.assistant;

import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.service.controller.admin.assistant.vo.ServiceAssistantRespVO;
import cn.iocoder.yudao.module.service.controller.admin.message.vo.ServiceMessageRespVO;
import cn.iocoder.yudao.module.service.dal.dataobject.assistant.ServiceAssistantDO;
import cn.iocoder.yudao.module.service.dal.dataobject.customer.ServiceCustomerDO;
import cn.iocoder.yudao.module.service.dal.dataobject.introconfig.ServiceIntroConfigDO;
import cn.iocoder.yudao.module.service.dal.dataobject.message.ServiceMessageDO;
import cn.iocoder.yudao.module.service.dal.dataobject.sceneconfig.SceneConfigDO;
import cn.iocoder.yudao.module.service.dal.dataobject.welcomeconfig.ServiceWelcomeConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Mapper
public interface AssistantConverter {

    AssistantConverter INSTANCE = Mappers.getMapper(AssistantConverter.class);

    default ServiceAssistantRespVO convert1(ServiceAssistantDO source, Map<Long, SceneConfigDO> sceneConfigDOMap, Map<Long, ServiceWelcomeConfigDO> welcomeConfigDOMap, Map<Long, ServiceIntroConfigDO> introConfigMap) {
        ServiceAssistantRespVO respVO = BeanUtils.toBean(source, ServiceAssistantRespVO.class);
        MapUtils.findAndThen(welcomeConfigDOMap, source.getWelcomeId(), (result) -> respVO.setWelcomeName(result.getConfigName()));
        MapUtils.findAndThen(sceneConfigDOMap, source.getSceneId(), (result) -> respVO.setSceneName(result.getName()));
        MapUtils.findAndThen(introConfigMap, source.getIntroConfigId(), (result) -> respVO.setIntroConfigName(result.getConfigName()));
        return respVO;
    }

    default PageResult<ServiceAssistantRespVO> convert(PageResult<ServiceAssistantDO> pageResult, Map<Long, SceneConfigDO> sceneConfigDOMap, Map<Long, ServiceWelcomeConfigDO> welcomeConfigDOMap, Map<Long, ServiceIntroConfigDO> introConfigDOMap) {
        PageResult<ServiceAssistantRespVO> newResult = new PageResult<>();
        newResult.setTotal(pageResult.getTotal());
        List<ServiceAssistantRespVO> newList = pageResult.getList().stream().map(v -> convert1(v, sceneConfigDOMap, welcomeConfigDOMap, introConfigDOMap)).collect(Collectors.toList());
        newResult.setList(newList);
        return newResult;
    }
}
